#include "NeoIcon.h"
#include <QFontDatabase>
#include <QPainter>

NeoIcon::NeoIcon(QObject *parent) : QObject(parent)
{
    QFontDatabase::addApplicationFont(":/NeoFluent/font/FontAwesomeSolid.otf");
    QFontDatabase::addApplicationFont(":/NeoFluent/font/FontAwesomeRegular.otf");
    QFontDatabase::addApplicationFont(":/NeoFluent/font/FontAwesomeBrands.otf");
}

NeoIcon::~NeoIcon() = default;

QIcon NeoIcon::getNeoIcon(NeoIconType::FontAwesomeSolid type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    return QIcon(getNeoPixmap(type, iconColor, pixelSize, fixedWidth, fixedHeight));
}

QIcon NeoIcon::getNeoIcon(NeoIconType::FontAwesomeRegular type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    return QIcon(getNeoPixmap(type, iconColor, pixelSize, fixedWidth, fixedHeight));
}

QIcon NeoIcon::getNeoIcon(NeoIconType::FontAwesomeBrands type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    return QIcon(getNeoPixmap(type, iconColor, pixelSize, fixedWidth, fixedHeight));
}

QPixmap NeoIcon::getNeoPixmap(NeoIconType::FontAwesomeSolid type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    QPixmap pixmap(fixedWidth, fixedHeight);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::TextAntialiasing);
    painter.setPen(iconColor);
    QFont font = QFont("Font Awesome 6 Free Solid");
    font.setPixelSize(pixelSize);
    painter.setFont(font);
    painter.drawText(pixmap.rect(), Qt::AlignCenter, QChar((unsigned short)type));
    painter.end();
    return pixmap;
}

QPixmap NeoIcon::getNeoPixmap(NeoIconType::FontAwesomeRegular type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    QPixmap pixmap(fixedWidth, fixedHeight);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::TextAntialiasing);
    painter.setPen(iconColor);
    QFont font = QFont("Font Awesome 6 Free Regular");
    font.setPixelSize(pixelSize);
    painter.setFont(font);
    painter.drawText(pixmap.rect(), Qt::AlignCenter, QChar((unsigned short)type));
    painter.end();
    return pixmap;
}

QPixmap NeoIcon::getNeoPixmap(NeoIconType::FontAwesomeBrands type, QColor iconColor, int pixelSize, int fixedWidth, int fixedHeight)
{
    QPixmap pixmap(fixedWidth, fixedHeight);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::TextAntialiasing);
    painter.setPen(iconColor);
    QFont font = QFont("Font Awesome 6 Brands Regular");
    font.setPixelSize(pixelSize);
    painter.setFont(font);
    painter.drawText(pixmap.rect(), Qt::AlignCenter, QChar((unsigned short)type));
    painter.end();
    return pixmap;
}